package org.xzx.shop_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.xzx.shop_api.entity.Collection;
import org.xzx.shop_api.mapper.CollectionMapper;
import org.xzx.shop_api.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CollectionServiceImpl implements CollectionService {
    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public int insertCollection(Collection collection) {
        return collectionMapper.insert(collection);
    }

    @Override
    public Collection getCollectByMemberIdGoodsId(int goodsId, int memberId ) {
        QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        queryWrapper.eq("goods_id", goodsId);
        return collectionMapper.selectOne(queryWrapper);
    }

    @Override
    public int deleteCollection(int goodsId, int memberId) {
        QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        queryWrapper.eq("goods_id", goodsId);
        return collectionMapper.delete(queryWrapper);
    }
}
